/**
 * @description 动态处理层
 */
const {
    createDynamic,
    getDynamicList
} = require('../services/dynamic')

const { SuccessModel, ErrorModel } = require('../model/ResModel')

const { PAGE_SIZE } = require('../conf/constant')

// const dynamicList = async () => {
//     // let sql = `
//     //             select * from dynamic 
//     // `
//     let sql = `select *
//     from dynamic a inner join dynamic_like b on a.id = b.dynamic_id`
//     return listData = await exec(sql)
// }

/**
 * @description 动态列表
 * @param {number} pageIndex 页数
 * @param {number} pageSize 查询数量
 */
async function dynamicList({
    pageIndex,
    pageSize = PAGE_SIZE
}) {
    const result = await getDynamicList({
        pageIndex,
        pageSize
    })
    return new SuccessModel(result)
}

/**
 * @description 创建动态
 * @param {*} param0 
 */
async function dynamicAdd({
    title,
    url,
    userId,
    type
}) {
    const result = await createDynamic({
        title,
        url,
        userId,
        type
    })
    return new SuccessModel()
}

/**
 * @description 我的动态列表
 * @param {*} param0 
 */
async function dynamicMyList({
    pageIndex,
    pageSize = PAGE_SIZE,
    userId
}){
    const dynamicMyData = await getDynamicList({pageIndex,pageSize,userId})
    return new SuccessModel(dynamicMyData)
}

module.exports = {
    dynamicList,
    dynamicAdd,
    dynamicMyList
}